<template>
  <div class="course_card">
    <div class="card_cont" @click="goPageCourseDetail(courseInfo.subject_id, courseInfo.subject_name)">
      <div class="card_title">
        <span class="course_name">{{courseInfo.subject_name}}</span>
        <span v-if="isStudy === -1" class="course_num">暂未开放</span>
        <span v-else class="course_num">共{{courseInfo.curriculum_count}}课程</span>
      </div>
      <div v-if="isStudy === -1" class="course_score not_open">
        <span class="score_num">0</span>
      </div>
      <div v-else class="course_score">
        <span class="score_num">{{totalScore|mathFloor}}</span>
        <span class="score_unit">分</span>
      </div>
      <div class="sum_score">总成绩</div>
      <div class="other_score">
        <div class="ol_score">
          <span class="score_txt">在线成绩</span>
          <span v-if="isStudy === -1">暂无</span>
          <span v-else>{{onlineScore|mathFloor}}分</span>
        </div>
        <i class="score_division"></i>
        <div class="ol_score">
          <span class="score_txt">期末成绩</span>
          <span v-if="isStudy === -1">暂无</span>
          <span v-else>{{endScore|mathFloor}}分</span>
        </div>
      </div>
    </div>
    <div class="card_bottom">
      <div v-if="courseInfo.term_time !== 0">
        <div class="end_test">
          <span class="time">期末考试&nbsp;{{courseInfo.term_time | timeFormat}}</span>
          <span class="time">{{courseInfo.duration}}分钟</span>
        </div>
        <div class="test_addr">
          考试地址&nbsp;{{courseInfo.address}}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CourseCard',
  props: {
    courseInfo: {
      type: Object,
      default() {
        return {}
      }
    },
    isStudy: {
      type: Number,
      default: -1
    }
  },
  computed: {
    totalScore() {
      return this.onlineScore + this.endScore
    },
    onlineScore() {
      return this.courseInfo.online_score * this.courseInfo.score_config.online_score / 100
    },
    endScore() {
      return this.courseInfo.term_score * this.courseInfo.score_config.term_score / 100
    },
  },
  methods: {
    // 跳转到课程详情页面
    goPageCourseDetail(subjectId, subjectName) {
      // 未开课的不能跳转
      if (this.isStudy === -1) return
      this.$router.push({
        path: '/courseDetail',
        query: {
          subject_id: subjectId,
          subject_name: subjectName
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .course_card {
    .card_cont {
      height: 158px;
      background: rgba(255, 255, 255, 1);
      border: 1px solid rgba(235, 235, 235, 1);
      box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.05);
      border-radius: 8px;
      box-sizing: border-box;
      padding: 10px;
      cursor: pointer;

      .card_title {
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        color: #666;
        line-height: 24px;
      }

      .course_score {
        font-size: 34px;
        color: #8BC34A;
        display: flex;
        justify-content: center;
        height: 28px;
        line-height: 28px;
        margin-top: 25px;

        .score_unit {
          padding-top: 14px;
          height: 14px;
          line-height: 14px;
          font-size: 14px;
        }
        &.not_open {
          color: #B4B4B4;
        }
      }

      .sum_score {
        font-size: 14px;
        color: #666;
        text-align: center;
        margin: 2px 0px 10px;
      }

      .other_score {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        color: #999;

        .ol_score {
          .score_txt {
            padding-right: 5px;
          }
        }

        .score_division {
          height: 8px;
          margin: 0 20px;
          border-right: 1px solid #B4B4B4;
        }
      }
    }

    .card_bottom {
      height: 50px;
      padding: 20px 10px 30px;
      font-size: 14px;
      color: #999;

      .end_test {
        display: flex;
        justify-content: space-between;
      }

      .test_addr {
        margin-top: 10px;
      }
    }
  }
</style>
